#!/bin/bash
echo "------start---------"
cd /home/docker
docker-compose stop moshme-service-$1
docker-compose rm -f moshme-service-$1
docker rmi docker-moshme-service-$1
docker-compose up -d moshme-service-$1
if [ ! -d "/home/docker/node/app/moshme" ];then
    mkdir /home/docker/node/app/moshme
fi
if [ ! -d "/home/docker/node/app/moshme/$1" ];then
    mkdir /home/docker/node/app/moshme/$1
fi
if [ -d "/home/docker/node/app/moshme/$1/moshme-ui" ];then
    rm -r -f /home/docker/node/app/moshme/$1/moshme-ui
fi
cp -r /home/docker/moshme/$1/moshme-ui /home/docker/node/app/moshme/$1
docker exec node bash -c "cd /home/node/app/moshme/$1/moshme-ui && yarn && yarn run build:$1"
if [ -d "/home/docker/nginx/html/moshme/$1/moshme-ui/dist" ];then
    rm -r -f /home/docker/nginx/html/moshme/$1/moshme-ui/dist
fi
cp -r /home/docker/node/app/moshme/$1/moshme-ui/dist /home/docker/nginx/html/moshme/$1/dist
echo "------end---------"
